/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.taobao.ibatiside.model.mapperv2.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.BasicFeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.InternalEList;

import org.taobao.ibatiside.model.mapperv2.Include;
import org.taobao.ibatiside.model.mapperv2.Mapperv2Package;
import org.taobao.ibatiside.model.mapperv2.SelectKey;
import org.taobao.ibatiside.model.mapperv2.TypeType;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Select Key</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getMixed <em>Mixed</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getGroup <em>Group</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getInclude <em>Include</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getKeyProperty <em>Key Property</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getResultClass <em>Result Class</em>}</li>
 *   <li>{@link org.taobao.ibatiside.model.mapperv2.impl.SelectKeyImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SelectKeyImpl extends EObjectImpl implements SelectKey {
	/**
	 * The cached value of the '{@link #getMixed() <em>Mixed</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMixed()
	 * @generated
	 * @ordered
	 */
	protected FeatureMap mixed;

	/**
	 * The default value of the '{@link #getKeyProperty() <em>Key Property</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKeyProperty()
	 * @generated
	 * @ordered
	 */
	protected static final String KEY_PROPERTY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getKeyProperty() <em>Key Property</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKeyProperty()
	 * @generated
	 * @ordered
	 */
	protected String keyProperty = KEY_PROPERTY_EDEFAULT;

	/**
	 * The default value of the '{@link #getResultClass() <em>Result Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getResultClass()
	 * @generated
	 * @ordered
	 */
	protected static final String RESULT_CLASS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getResultClass() <em>Result Class</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getResultClass()
	 * @generated
	 * @ordered
	 */
	protected String resultClass = RESULT_CLASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final TypeType TYPE_EDEFAULT = TypeType.PRE;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected TypeType type = TYPE_EDEFAULT;

	/**
	 * This is true if the Type attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean typeESet;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SelectKeyImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Mapperv2Package.Literals.SELECT_KEY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureMap getMixed() {
		if (mixed == null) {
			mixed = new BasicFeatureMap(this, Mapperv2Package.SELECT_KEY__MIXED);
		}
		return mixed;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureMap getGroup() {
		return (FeatureMap)getMixed().<FeatureMap.Entry>list(Mapperv2Package.Literals.SELECT_KEY__GROUP);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Include> getInclude() {
		return getGroup().list(Mapperv2Package.Literals.SELECT_KEY__INCLUDE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getKeyProperty() {
		return keyProperty;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setKeyProperty(String newKeyProperty) {
		String oldKeyProperty = keyProperty;
		keyProperty = newKeyProperty;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Mapperv2Package.SELECT_KEY__KEY_PROPERTY, oldKeyProperty, keyProperty));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getResultClass() {
		return resultClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setResultClass(String newResultClass) {
		String oldResultClass = resultClass;
		resultClass = newResultClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Mapperv2Package.SELECT_KEY__RESULT_CLASS, oldResultClass, resultClass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeType getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(TypeType newType) {
		TypeType oldType = type;
		type = newType == null ? TYPE_EDEFAULT : newType;
		boolean oldTypeESet = typeESet;
		typeESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Mapperv2Package.SELECT_KEY__TYPE, oldType, type, !oldTypeESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetType() {
		TypeType oldType = type;
		boolean oldTypeESet = typeESet;
		type = TYPE_EDEFAULT;
		typeESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, Mapperv2Package.SELECT_KEY__TYPE, oldType, TYPE_EDEFAULT, oldTypeESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetType() {
		return typeESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Mapperv2Package.SELECT_KEY__MIXED:
				return ((InternalEList<?>)getMixed()).basicRemove(otherEnd, msgs);
			case Mapperv2Package.SELECT_KEY__GROUP:
				return ((InternalEList<?>)getGroup()).basicRemove(otherEnd, msgs);
			case Mapperv2Package.SELECT_KEY__INCLUDE:
				return ((InternalEList<?>)getInclude()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Mapperv2Package.SELECT_KEY__MIXED:
				if (coreType) return getMixed();
				return ((FeatureMap.Internal)getMixed()).getWrapper();
			case Mapperv2Package.SELECT_KEY__GROUP:
				if (coreType) return getGroup();
				return ((FeatureMap.Internal)getGroup()).getWrapper();
			case Mapperv2Package.SELECT_KEY__INCLUDE:
				return getInclude();
			case Mapperv2Package.SELECT_KEY__KEY_PROPERTY:
				return getKeyProperty();
			case Mapperv2Package.SELECT_KEY__RESULT_CLASS:
				return getResultClass();
			case Mapperv2Package.SELECT_KEY__TYPE:
				return getType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Mapperv2Package.SELECT_KEY__MIXED:
				((FeatureMap.Internal)getMixed()).set(newValue);
				return;
			case Mapperv2Package.SELECT_KEY__GROUP:
				((FeatureMap.Internal)getGroup()).set(newValue);
				return;
			case Mapperv2Package.SELECT_KEY__INCLUDE:
				getInclude().clear();
				getInclude().addAll((Collection<? extends Include>)newValue);
				return;
			case Mapperv2Package.SELECT_KEY__KEY_PROPERTY:
				setKeyProperty((String)newValue);
				return;
			case Mapperv2Package.SELECT_KEY__RESULT_CLASS:
				setResultClass((String)newValue);
				return;
			case Mapperv2Package.SELECT_KEY__TYPE:
				setType((TypeType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Mapperv2Package.SELECT_KEY__MIXED:
				getMixed().clear();
				return;
			case Mapperv2Package.SELECT_KEY__GROUP:
				getGroup().clear();
				return;
			case Mapperv2Package.SELECT_KEY__INCLUDE:
				getInclude().clear();
				return;
			case Mapperv2Package.SELECT_KEY__KEY_PROPERTY:
				setKeyProperty(KEY_PROPERTY_EDEFAULT);
				return;
			case Mapperv2Package.SELECT_KEY__RESULT_CLASS:
				setResultClass(RESULT_CLASS_EDEFAULT);
				return;
			case Mapperv2Package.SELECT_KEY__TYPE:
				unsetType();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Mapperv2Package.SELECT_KEY__MIXED:
				return mixed != null && !mixed.isEmpty();
			case Mapperv2Package.SELECT_KEY__GROUP:
				return !getGroup().isEmpty();
			case Mapperv2Package.SELECT_KEY__INCLUDE:
				return !getInclude().isEmpty();
			case Mapperv2Package.SELECT_KEY__KEY_PROPERTY:
				return KEY_PROPERTY_EDEFAULT == null ? keyProperty != null : !KEY_PROPERTY_EDEFAULT.equals(keyProperty);
			case Mapperv2Package.SELECT_KEY__RESULT_CLASS:
				return RESULT_CLASS_EDEFAULT == null ? resultClass != null : !RESULT_CLASS_EDEFAULT.equals(resultClass);
			case Mapperv2Package.SELECT_KEY__TYPE:
				return isSetType();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (mixed: ");
		result.append(mixed);
		result.append(", keyProperty: ");
		result.append(keyProperty);
		result.append(", resultClass: ");
		result.append(resultClass);
		result.append(", type: ");
		if (typeESet) result.append(type); else result.append("<unset>");
		result.append(')');
		return result.toString();
	}

} //SelectKeyImpl
